home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / web / noweb / src / icon / elide.icn < prev    next >
Text File  |  1995-02-24  |  1KB  |  56 lines

  1. #line 13 "elide.nw"
  2. procedure main(args)
  3.   elide := []
  4.   every put(elide, globpat(!args))
  5.   while line := read() do
  6.     if match("@begin code ", line) then 
  7.       {
  8. #line 29 "elide.nw"
  9. accum := [line]
  10. while line := read() & not match("@defn ", line) do
  11.   put(accum, line)
  12. line ? {
  13.   ="@defn " | stop("This can't happen")
  14.   if globmatch(!elide) then {
  15.     while line := get(accum) | read() & not match("@end code ", line) do # drain
  16.       if line == "@nl" then write("@index nl")  # grotesque, but may keep lines right
  17.   } else
  18.     every write(!accum | line)
  19. }
  20. #line 18 "elide.nw"
  21.                                        }
  22.     else
  23.       write(line)
  24.   return
  25. end
  26. #line 55 "elide.nw"
  27. procedure globpat(s)
  28.   l := []
  29.   s ?
  30.     while not pos(0) do
  31.       put(l, 
  32.         if not any('?*') then
  33.           tab(upto('?*')|0)
  34.         else case move(1) of {
  35.           "?" : &cset
  36.           "*" : &null
  37.         })
  38.   return l
  39. end
  40. #line 73 "elide.nw"
  41. procedure doglobmatch(pat, i)
  42.   local p
  43.   suspend if p := pat[i] then
  44.     case type(p) of {
  45.       "string" : =p
  46.       "cset"   : tab(any(p))
  47.       "null"   : tab(&pos to *&subject+1)
  48.     } || doglobmatch(pat, i+1)
  49.   else (pos(0), "")
  50. end
  51. #line 87 "elide.nw"
  52. procedure globmatch(pattern, s)
  53.   return if \s then s ? doglobmatch(pattern, 1)
  54.          else doglobmatch(pattern, 1)
  55. end
  56.